package com.gxa.jjty.phy.controller;

import com.gxa.jjty.core.common.ExceptionCode;
import com.gxa.jjty.core.common.JsonResult;
import com.gxa.jjty.core.exception.BusinessException;
import com.gxa.jjty.core.util.StringUtil;
import com.gxa.jjty.phy.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 短信发送的服务接口
 * @ClassName SSMController
 * @Author: ws
 * @date 2021/11/29 15:23
 */
@RestController
@RequestMapping("/sms")
@Api(tags = "短信相关接口文档")
public class SmsController {

    @Autowired
    private SmsService smsService;

    @RequestMapping(value = "/send")
    @ApiOperation(value = "发送一键登录短信",notes = "发送一键登录短信",httpMethod = "POST")
    public Map sendLoginSms(@RequestParam("phone") String phone) throws BusinessException {
        if(!StringUtil.isPhoneNumber(phone)){
            throw new BusinessException(ExceptionCode.BAD_PHONE);
        }

        String smsCode = smsService.sendLoginSms(phone);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("短信发送成功");
        jsonResult.put("smsCode",smsCode);
        return jsonResult.getDataMap();
    }
}
